import java.util.Random;


public class Utils {
	private static Random rand = new Random(Math.abs(System.nanoTime()));
	public static void mutate(int[] genome, float mutationRate)
	{
		int    i;
		int mutated = 0;

		for (i=0; i<genome.length; i++)
		{
			if (rand.nextFloat() <= mutationRate)
			{
				genome[i] = 1 - genome[i];
				mutated++;
			}
		}
		//System.out.println("Mutated: " + mutated);
	}
	
	/*
	   one_pt_crossover:
	*/

	public static void one_pt_crossover(int[] gene, int[] mate)
	{
		int cut_point;
		int i;
		int[] temp = new int[gene.length];
		//make a copy to do the swap
		System.arraycopy(gene, 0, temp, 0, gene.length);
		cut_point = rand.nextInt(gene.length-2);
		for (i=cut_point+1; i<gene.length; i++)
			{
				gene[i] = mate[i];
				mate[i] = temp[i];
			}
		return;
	}


	

}
